//
//  TTTabarViewController.swift
//  WeiBo
//
//  Created by 涂永江 on 2017/6/4.
//  Copyright © 2017年 涂永江. All rights reserved.
//

import UIKit
import SVProgressHUD
class TTTabarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

       
    setUI()
    }

    func setUI()
    {
    
        //设置自定义的tabbar
        let tttabbar = TTTabView()
        
        //取出push时候的阴影
        tttabbar.backgroundImage = UIImage(named: "tabbar_background")
      
        
        //注意循环引用
        tttabbar.closore = { [unowned self] in
        
            if !TTHMUserAccountViewModel.sharedAccountModel.isaccess
            {
              SVProgressHUD.showInfo(withStatus: "请先登录,亲")
            return
            }
           
           let compose = TTComposeView()
            compose.show(Vc: self)
            
            
        }
        
        //要通过kvc进行赋值,因为不允许给系统属性赋值
        self.setValue(tttabbar, forKey: "tabBar")
        
        addChildViewController(childController: TTHomeViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(childController: TTMegseesViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(childController: TTDiscoverViewController(), title: "发现", imageName:"tabbar_discover")
     
        addChildViewController(childController: TTMeViewController(), title: "我的", imageName: "tabbar_profile")
    
    }
   
    //方法重载
    func addChildViewController(childController: UIViewController ,title:String , imageName:String) {
        
        //设置文字
        childController.title = title
        //设置文字颜色
        //1.方式
        UITabBar.appearance().tintColor = UIColor.orange
        //2.方式
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        //  设置文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 13)], for: .normal)
        //设置图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //设置选择图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        
        //设置nav的根控制器
        let nav = TTNavViewController(rootViewController: childController)
        //设置tab的子控制器
        addChildViewController(nav)
        
    }


    
}




